import request from './axios'

/**
 * 根据token获得用户信息
 * @returns {*}
 */
export const getUserInfo = () => {
    return request({
        url:'/auth/getUserInfo',
        method:'post'
    })
}
/**
 * 根据用户id获得权限菜单
 * @param userId
 * @returns {*}
 */
export const getMenuList = () => {
    return request({
        url:'/menu/list',
        method:'get'
    })
}
/**
 * 检查用户名是否存在
 * @param username
 * @returns {*}
 */
export const checkUserNameExist = (username) => {
    return request({
        url:'/user/checkUsernameExist',
        method:'get',
        params:{
            username
        }
    })
}
/**
 * 检查邮箱是否存在
 * @param username
 * @returns {AxiosPromise}
 */
export const checkEmailExist = (email) => {
    return request({
        url:'/user/checkEmailExist',
        method:'get',
        params:{
            email
        }
    })
}
/**
 * 用户注册
 * @param user
 * @returns {*}
 */
export const userRegister = (user={}) => {
    return request.post('/user/register',user);
}

/**
 * 激活用户
 * @param code
 * @returns {AxiosPromise}
 */
export const activeAccount = (code) => {
    return request({
        url:`/user/active/${code}`,
        method:'get'
    })
}
/**
 * 用户登陆
 * @param user
 * @returns {*}
 */
export const userLogin = (user={}) => {
    return request.post('/auth/login',user);
}

/**
 * 获得用户列表
 * @param data
 * @returns {AxiosPromise}
 */
export const getUserList = (data={}) => {
    return request.post('/user/userlist',data);
}

/**
 * 添加用户
 * @param email
 * @param available
 * @returns {AxiosPromise}
 */
export const insertUser = (email,available,type) => {
    return request.post('/user/admin/insert',{email,available,type});
}
/**
 * 修改用户
 * @param userId
 * @param available
 * @returns {AxiosPromise}
 */
export const updateUser = (userId,available) => {
    return request.post('/user/admin/update',{userId,available})
}

/**
 * 重置用户密码
 * @param userId
 * @param available
 * @returns {AxiosPromise}
 */
export const resetUserPwd = (userId) => {
    return request({
        url:`/user/resetPwd/${userId}`,
        method:'get'
    })
}

/**
 * 获得用户详细信息
 * @returns {AxiosPromise}
 */
export const getMyInfo = () => {
    return request({
        url:'/user/getMyInfo',
        method:'get'
    })
}
/**
 * 获得用户详细信息
 * @returns {AxiosPromise}
 */
export const getOtherUserInfo = (userId) => {
    return request({
        url:'/user/getUserInfo',
        method:'get',
        params:{
            userId
        }
    })
}

/**
 * 上传头像
 * @param formData
 * @returns {Promise<AxiosResponse<any>>}
 */
export const imgUpload = (formData) => {
    return request.post('/user/updateAvator',
        formData,
        {'Content-Type': 'application/x-www-form-urlencoded'})
}

/**
 * 修改用户信息
 * @param data
 * @returns {Promise<AxiosResponse<any>>}
 */
export const updateInfo = (data) => {
    return request.post('/user/updateInfo', data)
}

/**
 * 删除用户信息
 * @param userId
 * @returns {AxiosPromise}
 */
export const deleteUser = userId => {
    return request({
        url:'/user/deleteUser',
        method:'get',
        params:{
            userId
        }
    })
}

/**
 * 获得用户已有角色信息
 * @param userId
 * @returns {AxiosPromise}
 */
export const getUserHasRoleId = userId => {
    return request({
        url:'/user/getUserHasRoleId',
        method:'get',
        params:{
            userId
        }
    })
}

/**
 * 给用户授权
 * @param data
 * @returns {*}
 */
export const saveRoleToUser = data => {
    return request.post('/user/saveRoleToUser',data);
}

/**
 * 检查就密码是否正确
 * @param data
 * @returns {Promise<AxiosResponse<any>>}
 */
export const checkOldPassword = (data) => {
    return request.post('/user/checkOldPassword',data);
}

/**
 * 修改密码
 * @param data
 * @returns {Promise<AxiosResponse<any>>}
 */
export const updatePassword = (data) => {
    return request.post('/user/updatePassword',data);
}

/**
 * 给用户授衔
 * @param data
 * @returns {Promise<AxiosResponse<any>>}
 */
export const saveRankToUser = (data = {}) => {
    return request.post('/user/saveRankToUser',data);
}

/**
 * 获取用户已有头衔
 * @param userId
 */
export const getUserHasRankId = (userId) => {
    return request({
        url:'/user/getUserHasRankId',
        method:'get',
        params: {
            userId
        }
    })
}

/**
 * 退出登录
 * @returns {AxiosPromise}
 */
export const logOut = () => {
    return request({
        url:'/auth/logOut',
        method:'get'
    })
}

